package com.ftg.learn.lesson3;

import java.util.Scanner;

/**
 * 学习循环练习
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/6/8 上午9:05
 */
public class Homework03 {

    /**
     * 1题： 2+4+6+..100
     *
     * @return
     */
    public static int question01() {
        int sum = 0;
        for (int i = 2, max = 100; i < max; i += 2, max -= 2) {
            sum += (i + max);
        }
        return sum;
    }

    /**
     * (1+4*9)+(2+6*8)+(3+8*7)+(4+10*6)
     */
    public static int question02(int x) {
        int sum = 0;
        for (int i = 1, j = 4, k = 9; i <= x; i++, j += 2, k--) {
            sum += (i + j * k);
        }
        return sum;
    }


    /**
     * 3题： 假设一个数字可以被3和2整除，求出1-100之间有多少个这样的数字。 求个数
     */
    public static int question03() {
        int index = 0;
        for (int i = 6; i <= 100; i++) {
            if (i % 2 == 0 && i % 3 == 0) {
                index++;
            }
        }
        return index;
    }

    /**
     * 7题： 打印100以内 喝酒敲7的数 (带7 和 7的倍数)
     */
    public static void question07() {
        for (int i = 7; i <= 100; i++) {
            if (i % 7 == 0) {
                System.out.printf("%d==>是7的倍数\n", i);
            } else if (i % 10 == 7) {
                System.out.printf("%d==>个位是7\n", i);
            } else if (i / 10 == 7) {
                System.out.printf("%d==>十位是7\n", i);
            }
        }
    }

    /**
     * // 8题:  控制台输入一个int数举例（39）判断39以内 有没有喝酒敲7的数: 如果有把符合条件的数 拼成一个字符串最后打印
     * 如果没有 打印 没有
     */
    public static void question08() {
        Scanner s = new Scanner(System.in);
        System.out.println("请输入一个数");
        int num = s.nextInt();
        if (num < 7) {
            System.out.println("没有");
        } else {
            String mess = "";
            for (int i = 7; i <= num; i++) {
                if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7) {
                    mess += i + "\t";
                }
            }
            System.out.println(mess);
        }
    }

    public static void question09() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个正整数");

        int x = scanner.nextInt();
        int index = 0;
        for (int y = x; y > 0; y /= 10) {
            index++;
        }
        for (int i = 0; i < index; i++) {
            int f = x / (int) Math.pow(10, i) % 10;

            System.out.println(getWei(i) + "==>" + f);
        }
    }

    public static int pow(int x,int y){
        int sum = 1;
        for (int i = 0; i < y; i++) {
            sum *= x;
        }
        return sum;
    }

    public static String getWei(int i) {
        String wei = "";
        switch (i) {
            case 0:
                wei = "个位";
                break;
            case 1:
                wei = "十位";
                break;
            case 2:
                wei = "百位";
                break;
            case 3:
                wei = "千位";
                break;
            case 4:
                wei = "万位";
                break;
            case 5:
                wei = "十万位";
                break;
        }
        return wei;
    }

    public static void main(String[] args) {

        System.out.println(pow(8,2));
        System.out.println(question01());
        System.out.println(question02(4));
        System.out.println(question03());
        question07();
//        question08();
        question09();

        // 棒子 虎  鸡 虫



    }

}
